const { sys_address } = require("../../middleware/baseModel");

module.exports = {
  "GET /sys_address/index": async (ctx, next) => {
    let parent_id = ctx.get("parentId");
    const res = await sys_address.findAll({ where: { parent_id: parent_id } });
    return ctx.success(res);
  },

  "POST /sys_address/add": async (ctx, next) => {
    let row = ctx.getBody();
    const res = await sys_address.create(row);
    return ctx.success(res);
  },
  "POST /sys_address/edit": async (ctx, next) => {
    let row = ctx.getBody();
    let id = ctx.get("id");
    const res = await sys_address.update(row, {
      where: {
        id: id,
      },
      individualHooks: true,
    });

    return ctx.success(res);
  },
  "POST /sys_address/del": async (ctx, next) => {
    let id = ctx.get("id");
    const res = await sys_address.destroy({
      where: {
        id: id,
      },
    });
    return ctx.success(res);
  },
};
